/*
 * ZBrowser is an embeddable browser component.
 * Copyright (C) Author: Gangadhar Nagesh Metla (Novell, Inc.)
 * nmetla74@gmail.com 
 * Version 1.0
 * 1/3/2009
 * Filename InvokePropPageCmdDlg.java
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.novell.zenworks.agent.zbrowser.cmddialogs;

import javax.swing.JFrame;

import com.novell.zenworks.agent.zbrowser.NavigationUtils;

public class InvokePropPageCmdDlg
{
    private JFrame frame;
    private String  _busyCaption;
    private String  _successCaption;
    private String  _errorCaption;
    private String  _errorDescription;
    private String  _successDescription;
    private String  _title;
    private String _pageId;
    private String _cmdData;
   //private boolean _success = false;
    public PropPageCmdDialog busyDlg = null;
    
    public InvokePropPageCmdDlg(JFrame frame)
    {
        this.frame = frame;
    }
      
    public String getBusyCaption()
    {
        return _busyCaption;
    }
    public void setBusyCaption(String caption)
    {
        _busyCaption = caption;
    }
    public String getSuccessCaption()
    {
        return _successCaption;
    }
    public void setSuccessCaption(String caption)
    {
        _successCaption = caption;
    }
    public String getErrorCaption()
    {
        return _errorCaption;
    }
    public void setErrorCaption(String caption)
    {
        _errorCaption = caption;
    }
    public String getErrorDescription()
    {
        return _errorDescription;
    }
    public void setErrorDescription(String description)
    {
        _errorDescription = description;
    }
    public String getSuccessDescription()
    {
        return _successDescription;
    }
    public void setSuccessDescription(String description)
    {
        _successDescription = description;
    }
    
    public String getTitle()
    {
        return _title;
    }
    
    public void setTitle(String _title)
    {
        this._title = _title;
    }
    
    public void executeCommand(String pageId, String cmdData)
    {
        setPageId(pageId);
        setCmdData(cmdData);
        try
        {
            callPageMethod();
            //_success = true;
        } catch (Exception e)
        {
            showError(e.getMessage());
            //_success = false;
        }
    }

    
    
    public void showError(String error)
    {
        _errorDescription = error;
        //_success = false;
        //ShowDialog(owner);
    }

    public void showSuccess(String successMessage, boolean success)
    {
        _successDescription = successMessage;
        //_success = success;
        //base.ShowDialog(owner);
    }
    
    public void showBusy()
    {
        if(busyDlg == null)
        {
            busyDlg = new PropPageCmdDialog(frame, _busyCaption, _title, PropPageCmdDialog.BUSY, null, true);
        }
    }
    
    public void setPageId(String _pageId)
    {
        this._pageId = _pageId;
    }

    public String getPageId()
    {
        return _pageId;
    }

    public void setCmdData(String _cmdData)
    {
        this._cmdData = _cmdData;
    }

    public String getCmdData()
    {
        return _cmdData;
    }

    private void callPageMethod() throws Exception
    {
        showBusy();
        PropPageCmdDialogLauncher cmdExec = new PropPageCmdDialogLauncher(this);
        //Object retVal = (Object) NavigationUtils.getServer().invokePropPageCommand(_pageId, _cmdData);
        Thread t = new Thread(cmdExec);
        t.start();
        busyDlg.setVisible(true);
        busyDlg = null;
        
       /* if(busyDlg != null) 
        {
            Thread.sleep(15000);
            busyDlg.dispose();
            busyDlg = null;
        }*/
        
        //if(retVal != null)
        {
            //show success message
        }
        //else
        {
            //showError(retVal.toString());
        }
        //ShowResults(retVal as string); //show success or failure
    }
}
